package com.shihb.behavioralpatterns.iteratorpattern;

import java.util.Iterator;

/**
 *Description:
 *Version:1.0.0
 *@author shihb
 *@date 2020/7/28 19:29
 */
public class InfoIterator implements Iterator {
  private Department[] departments;
  private int index;

  public InfoIterator(Department[] departments) {
    this.departments = departments;
    index=-1;
  }

  @Override
  public boolean hasNext() {
    index++;
    if(index>=departments.length || departments[index]==null){
      return false;
    }
    return true;
  }

  @Override
  public Object next() {
    return departments[index];
  }
}
